﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Dropthings.DAL;

namespace Dropthings.Business.Facade
{
    partial class Facade
    {
        public DataSet GetOrganizeBaseInfo()
        {
            UQ_GetOrganizeBaseInfo query = new UQ_GetOrganizeBaseInfo();
            DataSet ds = query.ExecuteDataset();
            DataSet newDs = ds.Clone();
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                if (!string.IsNullOrEmpty(Context.CurrentUserName))
                {
                    Guid userGuid = GetUserGuidFromUserName(Context.CurrentUserName);

                    UQ_GetUserOrganizeIdentify uq = new UQ_GetUserOrganizeIdentify(userGuid);
                    object obj = uq.ExecuteScalar();
                    string identify = string.Empty;
                    if (obj != null)
                        identify = obj.ToString();
                    if (identify == "000")
                    {
                        DataTable dt = newDs.Tables[0];
                        DataRow dr = dt.NewRow();
                        dr[0] = "全部建筑";
                        dr[1] = "-1";
                        dt.Rows.Add(dr);
                        foreach (DataRow oldDr in ds.Tables[0].Rows)
                        {
                            DataRow drnew = dt.NewRow();
                            drnew[0] = oldDr[0];
                            drnew[1] = oldDr[1];
                            dt.Rows.Add(drnew);
                        }
                    }
                    else if (!string.IsNullOrEmpty(identify))
                    {
                        foreach (DataRow oldDr in ds.Tables[0].Rows)
                        {
                            if (oldDr[1].ToString() == identify)
                            {
                                DataTable dt = newDs.Tables[0];
                                DataRow drnew = dt.NewRow();
                                drnew[0] = oldDr[0];
                                drnew[1] = oldDr[1];
                                dt.Rows.Add(drnew);
                                break;
                            }
                        }
                    }
                }
            }
            return newDs;
        }

        public DataSet GetOrganizePeropertyInfo(string PropertyCode)
        {
            UQ_GetOrganizePorpertyInfo query = new UQ_GetOrganizePorpertyInfo(PropertyCode);
            return query.ExecuteDataset();
        }

        public DataSet GetOrganizeBaseInfoNoHandle()
        {
            UQ_GetOrganizeBaseInfo query = new UQ_GetOrganizeBaseInfo();
            return query.ExecuteDataset();
        }

        public DataSet GetOrganizeBaseInfo(string identifyCode)
        {
            UQ_GetOrganizeBaseInfoForReportView query = new UQ_GetOrganizeBaseInfoForReportView(identifyCode);
            return query.ExecuteDataset();
        }
    }
}
